package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2019/1/15 17:45
 * @description
 */
public class Code860 {
    private int[] money = {0, 0};

    public boolean lemonadeChange(int[] bills) {
        for (int bill : bills) {
            if (bill == 5) {
                money[0]++;
            }
            if (bill == 10) {
                if (money[0] < 1) {
                    return false;
                }
                money[0]--;
                money[1]++;
            }
            if (bill == 20) {
                if (money[0] > 2 || (money[1] > 0 && money[0] > 0)) {
                    if (money[1] > 0) {
                        money[1]--;
                        money[0]--;
                    } else {
                        money[0] -= 3;
                    }
                } else {
                    return false;
                }
            }
        }
        return true;
    }
}
